﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

using Sita.Data.Context;
using Sita.Entities;

namespace Sita.Data.Repositories
{
    public class PermissionRepository : GenericRepository<Permission>
    {

        public PermissionRepository() :
            base(new SitaContext())
        { }

        public IList<Permission> GetByUserID(int userID)
        {
            SitaContext _context = new SitaContext();
            IList<Permission> UserPermissions;

            UserPermissions = _context.Permissions
                .Join(_context.UserPermissions, p => p.PermissionID, up => up.PermissionID, (p, up) => new { p, up })
                .Where(up => up.up.UserID == userID)
                .Select(p => p.p)
                .ToList();

            return UserPermissions;
        }
    }
}
